package day3;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

//模拟scanner对象获取控制台数据 next() nextInt()
public class TestScanner {
    public InputStream is;
    public BufferedReader br;
    //有参构造
    public TestScanner(InputStream is){
        this.is=is;
        InputStreamReader isr=new InputStreamReader(is);//把字节输入流变为字符输入流
        br=new BufferedReader(isr);//可以进行读取
    }
    public String next(){
        String msg= null;
        try {
            msg = br.readLine();//读取一行
        } catch (IOException e) {
            e.printStackTrace();
        }
        return msg;
    }
    public int nextInt(){
        String msg= null;
        try {
            msg = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        int result=Integer.parseInt(msg);
        return result;
    }
    public static void main(String[] args) throws IOException {
        //System.in 表示系统输入流 可以获取控制台数据 本质上是一个字节输入流
        //Scanner sc=new Scanner(System.in);
        TestScanner ts=new TestScanner(System.in);
        InputStream is=System.in;//字节输入流
        InputStreamReader isr=new InputStreamReader(is);
        BufferedReader br=new BufferedReader(isr);
        while(true){
            System.out.println("输入内容");
            String msg=br.readLine();
            System.out.println("读取控制台数据"+msg);
        }
    }
}
class Test{
    public static void main(String[] args) {
        TestScanner ts=new TestScanner(System.in);
        System.out.println("请输入姓名");
        String name=ts.next();
        System.out.println("请输入年龄");
        int age=ts.nextInt();
        System.out.println(name+"  "+age);
    }
}
